local hewozaiyiqi = fk.CreateSkill{
    name = "ym1__hewozaiyiqi",
}
Fk:loadTranslationTable{
    ["ym1__hewozaiyiqi"] = "和我在一起！",
    [":ym1__hewozaiyiqi"] = "出牌阶段限一次，你可视为使用一张无距离限制的【推心置腹】，然后对目标使用以此获得的任意张即时牌。",
    ["#ym1__hewozaiyiqi"] = "和我在一起！：视为使用一张【推心置腹】，然后对目标使用以此获得的任意张即时牌",
    ["#ym1__hewozaiyiqi-use"] = "和我在一起！：你可以对目标使用你以此获得的任意张即时牌",
    ["@@ym1__hewozaiyiqi-inarea-phase"] = "和我在一起！",

    ["$ym1__hewozaiyiqi1"] = "我只是要你留下来，和我在一起。",
    ["$ym1__hewozaiyiqi2"] = "你还是什么都不懂...哈哈哈！",
}
hewozaiyiqi:addEffect("active",{
    anim_type = "support",
    prompt = "#ym1__hewozaiyiqi",
    min_target_num = 1,
    card_filter = Util.FalseFunc,
    mute = true,
    target_filter = function(self, player, to_select, selected, selected_cards)
        local c = Fk:cloneCard("ym__sincere_treat")
        c.skillName = hewozaiyiqi.name
        return c.skill:targetFilter(player, to_select, selected, selected_cards, c, nil) and
        not player:isProhibited(Fk:currentRoom():getPlayerById(to_select.id), c)
    end,
    on_use = function(self, room, effect)
        local player = room:getPlayerById(effect.from.id)
        local c = Fk:cloneCard("ym__sincere_treat")
        c.skillName = hewozaiyiqi.name
        local use = {
            from = player,
            tos = effect.tos,
            card = c,
            --extra_data = {ym1__hewozaiyiqi_user = player.id},
        }
        room:notifySkillInvoked(player,hewozaiyiqi.name,"support")
        player:broadcastSkillInvoke(hewozaiyiqi.name,1)
        room:useCard(use)
        if player.dead then return end
        while #player:getCardIds(Player.Hand) > 0 and #table.filter(player:getCardIds(Player.Hand), function (id)
            return Fk:getCardById(id):getMark("@@ym1__hewozaiyiqi-inarea-phase") > 0
        end) > 0 do
            p("---")
            local Cards = {}
            for _, id in ipairs(table.filter(player:getCardIds(Player.Hand), function (id)
                return Fk:getCardById(id):getMark("@@ym1__hewozaiyiqi-inarea-phase") > 0
            end)) do
                local card = Fk:getCardById(id)
                if not player:prohibitUse(card) and player:canUse(card, {bypass_times = true})  and (card.type == Card.TypeBasic or card:isCommonTrick()) then
                    --[[if card.trueName == "slash" or table.filter(effect.tos, function (tp)
                        return card.skill and card.skill.targetFilter and (card.skill:targetFilter(tp, {}, {}, c, nil, player) or card.skill:targetFilter(tp, {}, {}, c, nil, room:getPlayerById(tp)))
                    end) then]]--
                    table.insertIfNeed(Cards, id)
                    --end
                end
            end
            local use2 = room:askToUseRealCard(player,{
                pattern = Cards,
                skill_name = hewozaiyiqi.name,
                prompt = "#ym1__hewozaiyiqi-use",
                extra_data = {
                    exclusive_targets = table.map(effect.tos, function (pid) return pid.id end),
                    bypass_times = true,
                    bypass_distances = true,
                },
                cancelable = true,
                skip = true,
            })
            if use2 then
                player:broadcastSkillInvoke(hewozaiyiqi.name,2)
                local toss = {}
                for _,pid in ipairs(use2.tos) do
                    if table.contains(table.map(effect.tos, function (id) return {id} end),pid.id) then
                        table.insert(toss,pid)
                    end
                end
                if #toss == 0 then toss = effect.tos end
                use2.tos = toss
                room:useCard(use2)
            else
                break
            end
        end
        for _, id in ipairs(table.filter(player:getCardIds(Player.Hand), function (id)
            return Fk:getCardById(id):getMark("@@ym1__hewozaiyiqi-inarea-phase") > 0
        end)) do
            local card = Fk:getCardById(id)
            room:setCardMark(card, "@@ym1__hewozaiyiqi-inarea-phase", 0)
        end
      end,
    can_use = function (self, player)
        return player:usedSkillTimes(hewozaiyiqi.name, Player.HistoryPhase) == 0
    end,
})
hewozaiyiqi:addEffect(fk.AfterCardsMove,{
    can_refresh = function(self, event, target, player, data)
        local e = player.room.logic:getCurrentEvent():findParent(GameEvent.CardEffect)
        if e and player:hasSkill("ym1__hewozaiyiqi") then
            local use = e.data
            if table.contains(use.card.skillNames, "ym1__hewozaiyiqi") then
                for _, move in ipairs(data) do
                    if move.toArea == Card.PlayerHand then
                        if move.to == player then
                            for _, info in ipairs(move.moveInfo) do
                                if table.contains(player:getCardIds("h"), info.cardId) then
                                    player.room:setCardMark(Fk:getCardById(info.cardId, true), "@@ym1__hewozaiyiqi-inarea-phase", 1)
                                else
                                    player.room:setCardMark(Fk:getCardById(info.cardId, true), "@@ym1__hewozaiyiqi-inarea-phase", 0)
                                end
                            end
                        else
                            for _, info in ipairs(move.moveInfo) do
                                if table.contains(player:getCardIds("h"), info.cardId) then
                                    player.room:setCardMark(Fk:getCardById(info.cardId, true), "@@ym1__hewozaiyiqi-inarea-phase", 1)
                                else
                                    player.room:setCardMark(Fk:getCardById(info.cardId, true), "@@ym1__hewozaiyiqi-inarea-phase", 0)
                                end
                            end
                        end
                    end
                end
            end
        end
    end,
})
hewozaiyiqi:addEffect("targetmod",{
    bypass_distances = function(self, player, skill, card)
        return card and table.contains(card.skillNames, "ym1__hewozaiyiqi")
    end,
})
return hewozaiyiqi